package com.runda.biz.controller;

import java.util.List;

import javax.annotation.Resource;

import com.bbjob.dto.Result;
import com.bbjob.model.ProductQuotationRecord;
import com.runda.biz.service.IProductQuotationRecordService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import tk.mybatis.mapper.entity.Example;


@RestController
@RequestMapping("production/quotationRecord")
public class ProductQuotationRecordController{
    @Resource
    private IProductQuotationRecordService quotationRecordService;

    @PostMapping("list/save/{productId}")
    public Result<String> saveAll(@RequestBody List<ProductQuotationRecord> list,@PathVariable("productId") Integer productId){
        int ok=quotationRecordService.saveAll(list,productId);
        if(ok>0){
            return new Result<String>();
        }
        return Result.GLOBAL_ERROR();
    }
    @GetMapping("list/{productId}")
    public Result<List<ProductQuotationRecord>> listBy(@PathVariable("productId") Integer productId){
        List<ProductQuotationRecord> list=this.quotationRecordService.selectByProperty("productId", productId, ProductQuotationRecord.class,"report_time desc");
            return new Result<List<ProductQuotationRecord>>(list);
    }
    @GetMapping(value="del/{id}")
    public Result<String> delQuotationRecord(@PathVariable("id") Integer id) {
        int ok=this.quotationRecordService.delete(id);
        if(ok>0){
            return new Result<String>();
        }
        return Result.GLOBAL_ERROR();
    }
    @PostMapping(value="save/{productId}")
    public Result<String> saveQuotationRecord(@PathVariable("productId")Integer productId, @RequestBody ProductQuotationRecord quotationRecord) {
        quotationRecord.setProductId(productId);
        int ok=this.quotationRecordService.save(quotationRecord);
        if(ok>0){
            return new Result<String>();
        }
        return Result.GLOBAL_ERROR();
    }
}